home *** CD-ROM | disk | FTP | other *** search
/ Amiga Packmags / NewsFlash - Issue 19 (1991-08)(UGA - NewsFlash UK)(Disk 1 of 2).zip / NewsFlash - Issue 19 (1991-08)(UGA - NewsFlash UK)(Disk 1 of 2).adf / spyhead / SpyHead.c.pp / SpyHead.c
C/C++ Source or Header  |  1978-01-06  |  11KB  |  358 lines

  1. /**************************************************************************/
  2. /**        SpyHead.c (SYSGADS) Apr 1991  L.v.Jeurissen  (LvJ)           **/
  3. /**************************************************************************/
  4.  
  5. /**************************************************************************/
  6. /** Spy Head V1.0 is a easy useable and nice looking program that shares **/
  7. /** with you the information, on wich place the read/write head actually **/
  8. /** is. When you insert a disk in a drive Spy head changes to that drive **/
  9. /** to spy the drives head. The JumpScreen gadget, will open Spy Head's  **/
  10. /** window in the next Screen if it is available and not to small.       **/
  11. /** I have some questions :  Who knows why MANX detach.o gurus by an     **/
  12. /** exit() call on an A1000 and that only with the shell. Is it my error **/
  13. /** (look between #ifndef A1000 and #endif) or is it a bug in _main.c /  **/
  14. /** _exit.c  look in directory sysio.arc from the MANX library sources.     **/
  15. /** Let me know if you have the right answer. In advance a big thank to  **/
  16. /** the people, who wants to look in to that problem. THANK YOU !        **/
  17. /** Another question is this one: After I Write some text to the CLI/    **/
  18. /** Shell the prompt won't return after a `\n', this is a common problem **/
  19. /** because lot's of people (programmers) know the problem, but they     **/
  20. /** can't give me the right answer! WHO CAN! In this case I used a `\r'  **/
  21. /** because it looks nicer than a missing prompt.                        **/
  22. /** The same rules as for Spy Mouse V1.0 are valid: Anyone may sell this **/
  23. /** proggy (only  for big  money, and only to idiots who want to get rid **/
  24. /** of their money), sell (only idiots), throw away, change, etc.        **/
  25. /** I won't feel, and act responsable for any damage or losses of goods  **/
  26. /** and lives that this program may cause.  EVER!!             **/
  27. /** Good criticism and tips are however welcome. If you find flow        **/
  28. /** errors or code that could be better or quicker let me know, it's     **/
  29. /** a hobby, but I'am eager to learn new things.                         **/
  30. /**                                     **/
  31. /** You feel like giving away some money?      Send it to GreenPeace. **/
  32. /**                                     **/
  33. /** All those seadogs are freezing to death without a warm coat, so     **/
  34. /** support those freezing annimals outthere. They supported us long     **/
  35. /** enough so now its our turn to support them. Buy them a warm furr !!  **/
  36. /**                                     **/
  37. /** SeaBirds don't want a oilcoat they have one themselves.              **/
  38. /**                                     **/
  39. /** Support me also, not with money, but with bug reports, tips. If you  **/
  40. /** find big errors in the source? let me know. You scratch my back and  **/
  41. /** I will scratch yours. You invented a wheel let me know, maybe I can  **/
  42. /** use it to build a car.                         **/
  43. /**                                     **/
  44. /** Apr 20 23:07:10 1991            L.V. Jeurissen         **/
  45. /**                        Paterstraat 35         **/
  46. /**                        6828 AG  Arnhem      **/
  47. /**                        085-455693         **/
  48. /**                        Nederland         **/
  49. /**************************************************************************/
  50.  
  51. #include "Data.c"
  52.  
  53. #ifndef A1000
  54. #define EGOSTRING "\x9B1mSpy Head V1.0\x9B0m  (c) Apr 1991 by \x9B1mL\x9B0mars \x9B1mV\x9B0man \x9B1mJ\x9B0meurissen\r"
  55. #define EGOSTRLEN (long) sizeof(EGOSTRING)
  56. #endif
  57. #define BLOCKS(ACTTRK,ACTSEC) ((ACTTRK * (UWORD) NUMSECS) + ACTSEC)
  58. #define WAITSEC 0L
  59. #define WAITMIC 125000L
  60.  
  61. void _wb_parse()
  62. {
  63. }
  64. void _cli_parse()
  65. {
  66. }
  67.  
  68. void main();
  69. void LoopThisCode();
  70. void SpyHead();
  71. void ChangeDriveNumber();
  72. void FillITextBuffer();
  73. void NumberToBuffer();
  74. void AudioInform();
  75. void WakeMeUpService();
  76. void JumpToNextScreen();
  77. void OpenWindowCheck();
  78. void CloseWindowCheck();
  79. void DoThisCodeFirst();
  80. void DoThisCodeLast();
  81.  
  82. struct IntuitionBase *IntuitionBase = NULL;
  83. struct GfxBase *GfxBase = NULL;
  84. struct Window *Window = NULL;
  85. struct Screen *Screen = NULL;
  86. struct IOStdReq *DiskIO = NULL, *TimerIO = NULL;
  87. struct Device *DiskDevice = NULL;
  88. struct MsgPort *DiskPort = NULL, *TimerPort = NULL;
  89.  
  90. USHORT *ChipImageBlock = NULL;
  91. UWORD DriveNumber = 0, Sektor = 0, Track = 0;
  92. ULONG TimerSignal = NULL;
  93. static ULONG DiskChange[NUMUNITS] = {0L, 0L, 0L, 0L};
  94. static UBYTE TRACKDISKNAME[] = TD_NAME;
  95.  
  96. #ifndef A1000
  97. extern BPTR _Backstdout;
  98. long _BackGroundIO = 1L;
  99. long _stack = 1536L + 256L;
  100. char *_procname = "Spy Head V1.0";
  101. long _priority = 0L;
  102. #endif
  103.  
  104. void main()
  105. {
  106.     DoThisCodeFirst();
  107.     LoopThisCode();
  108. }
  109.  
  110. void LoopThisCode()
  111. {
  112.     register struct IntuiMessage *message;
  113.     register ULONG Class;
  114.     register APTR IAddress;
  115.     register int count;
  116.  
  117.     WakeMeUpService(WAITSEC, WAITMIC);
  118.  
  119.     while (TRUE) {
  120.  
  121.     if (Wait(1L << Window->UserPort->mp_SigBit | TimerSignal) & TimerSignal) {
  122.         GetMsg(TimerPort);
  123.         SpyHead();
  124.         WakeMeUpService(WAITSEC, WAITMIC);
  125.     }
  126.     while (message = (struct IntuiMessage *) GetMsg(Window->UserPort)) {
  127.  
  128.         Class = message->Class;
  129.         IAddress = message->IAddress;
  130.  
  131.         ReplyMsg((struct Message *) message);
  132.         switch (Class) {
  133.         case CLOSEWINDOW:
  134.         while (message = (struct IntuiMessage *) GetMsg(Window->UserPort))
  135.             ReplyMsg((struct Message *) message);
  136.         DoThisCodeLast(RETURN_OK);
  137.         break;
  138.         case DISKINSERTED:
  139.         for (count = 0; count < NUMUNITS; count++) {
  140.             if (DiskChange[count] == FALSE)
  141.             continue;
  142.             if (OpenDevice(TRACKDISKNAME, (long) count, (struct IOStdReq *) DiskIO, TDB_ALLOW_NON_3_5) > NULL)
  143.             continue;
  144.             else {
  145.             DiskIO->io_Command = TD_CHANGESTATE;
  146.             DoIO(DiskIO);
  147.             if (DiskIO->io_Actual != NULL) {
  148.                 CloseDevice(DiskIO);
  149.                 continue;
  150.             }
  151.             DiskIO->io_Command = TD_CHANGENUM;
  152.             DoIO(DiskIO);
  153.             if (DiskIO->io_Actual != DiskChange[count]) {
  154.                 DiskChange[count] = DiskIO->io_Actual;
  155.                 CloseDevice(DiskIO);
  156.                 DriveNumber = (UWORD) count;
  157.                 break;
  158.             }
  159.             CloseDevice(DiskIO);
  160.             }
  161.         }
  162.         AudioInform();
  163.         break;
  164.         case GADGETUP:
  165.         if (IAddress == (APTR) & ChangeDriveGadget) {
  166.             ChangeDriveNumber();
  167.             break;
  168.         }
  169.         if (IAddress == (APTR) & JumpScreenGadget) {
  170.             JumpToNextScreen();
  171.             break;
  172.         }
  173.             default:
  174.                 break;
  175.         }
  176.     }
  177.     }
  178. }
  179.  
  180. #asm
  181.     public    _SpyHead
  182. _SpyHead:
  183.     link    a5,#$0
  184.     movem.l lb3,-(sp)
  185.     move.l    _DiskDevice,a0
  186.     moveq.l #$0,d0
  187.     move.w    _DriveNumber,d0
  188.     asl.w    #$2,d0
  189.     movea.l $24(a0,d0.w),a1
  190.     cmpa.l    #$0,a1
  191.     beq.s    lb1
  192.     move.w    $48(a1),_Sektor
  193.     move.w    $4a(a1),_Track
  194.     jsr    _FillITextBuffer
  195.     bra.s    lb2
  196. lb1:    jsr    _ChangeDriveNumber
  197.     jsr    _AudioInform
  198. lb2:    movem.l (sp)+,lb3
  199.     unlk    a5
  200.     rts
  201. lb3:    reg    a0-a6/d0-d7
  202. #endasm
  203.  
  204. void ChangeDriveNumber()
  205. {
  206.     DriveNumber++;
  207.     if (DriveNumber > 3)
  208.     DriveNumber = 0;
  209. }
  210.  
  211. void FillITextBuffer()
  212. {
  213.     register int count;
  214.     static char temp[27] = " B:0000  T:000  S:00  DF0: ";
  215.  
  216.     for (count = 0; count < 27; count++)
  217.     buffer[count] = temp[count];
  218.  
  219.     NumberToBuffer(6, BLOCKS(Track, Sektor));
  220.     NumberToBuffer(13, Track);
  221.     NumberToBuffer(19, Sektor);
  222.     NumberToBuffer(24, DriveNumber);
  223.     PrintIText(Window->RPort, &IText, 26L, 1L);
  224. }
  225.  
  226. void NumberToBuffer(count, Number)
  227. register int count, Number;
  228. {
  229.     do {
  230.     buffer[count] = ((int) (Number % 10) + 0x30);
  231.     count--;
  232.     } while ((Number /= 10) != 0);
  233. }
  234.  
  235. void AudioInform()
  236. {
  237.     *(UWORD *) 0xdff0a0 = *(UWORD *) (ChipImageBlock + 680L);
  238.     *(UWORD *) 0xdff0a4 = 0x0004;
  239.     *(UWORD *) 0xdff0a8 = 0x0040;
  240.     *(UWORD *) 0xdff0a6 = 0x01BF;
  241.     *(UWORD *) 0xdff096 = 0x8201;
  242.     Delay(5L);
  243.     *(UWORD *) 0xdff096 = 0x0001;
  244. }
  245.  
  246. void WakeMeUpService(S, M)
  247. ULONG S, M;
  248. {
  249.     TimerIO->io_Command = TR_ADDREQUEST;
  250.     TimerIO->io_Actual = S;
  251.     TimerIO->io_Length = M;
  252.     SendIO(TimerIO);
  253. }
  254.  
  255. void JumpToNextScreen()
  256. {
  257.     Screen = Window->WScreen->NextScreen;
  258.     if (Screen && Screen->Width > 340) {
  259.         ScreenToBack(Window->WScreen);
  260.         ScreenToFront(Screen);
  261.         CloseWindowCheck();
  262.         OpenWindowCheck(Screen);
  263.     } else
  264.         AudioInform();
  265. }
  266.  
  267. void OpenWindowCheck(NWS)
  268. struct Screen *NWS;
  269. {
  270.     NewWindow.Screen = NWS;
  271.     if ((Window = (struct Window *) OpenWindow(&NewWindow)) == NULL)
  272.         DoThisCodeLast(RETURN_WARN);
  273. }
  274.  
  275. void CloseWindowCheck()
  276. {
  277.     if (Window) {
  278.     RemoveGList(Window, &CloseWindowGadget, -1L);
  279.     CloseWindow(Window);
  280.     }
  281. }
  282.  
  283. void DoThisCodeFirst()
  284. {
  285.     register int count;
  286.  
  287.     if ((TimerPort = (struct MsgPort *) CreatePort(0L, 0L)) == NULL)
  288.     DoThisCodeLast(RETURN_WARN);
  289.     if ((TimerIO = (struct IOStdReq *) CreateStdIO(TimerPort)) == NULL)
  290.     DoThisCodeLast(RETURN_WARN);
  291.     if (OpenDevice(TIMERNAME, UNIT_VBLANK, (struct StdIOReq *) TimerIO, 0L) > NULL)
  292.     DoThisCodeLast(RETURN_WARN);
  293.     TimerSignal = 1L << TimerPort->mp_SigBit;
  294.     if ((DiskPort = (struct MsgPort *) CreatePort(0L, 0L)) == NULL)
  295.     DoThisCodeLast(RETURN_WARN);
  296.     if ((DiskIO = (struct IOStdReq *) CreateStdIO((struct MsgPort *) DiskPort)) == NULL)
  297.     DoThisCodeLast(RETURN_WARN);
  298.     for (count = 0; count < NUMUNITS; count++) {
  299.     if (OpenDevice(TRACKDISKNAME, (long) count, (struct StdIOReq *) DiskIO, TDB_ALLOW_NON_3_5) > NULL)
  300.         DiskChange[count] = FALSE;
  301.     else {
  302.         if (count == 0)
  303.         DiskDevice = DiskIO->io_Device;
  304.         DiskIO->io_Command = TD_CHANGENUM;
  305.         DoIO(DiskIO);
  306.         DiskChange[count] = DiskIO->io_Actual;
  307.         CloseDevice(DiskIO);
  308.     }
  309.     }
  310.     if ((ChipImageBlock = (USHORT *) AllocMem(1368L, MEMF_CHIP)) == NULL)
  311.     DoThisCodeLast(RETURN_WARN);
  312.     movmem(ImageBlock, ChipImageBlock, 1368);
  313.     ChangeDriveImage.ImageData = (USHORT *) (ChipImageBlock + 0L);
  314.     ChangeDriveSelectImage.ImageData = (USHORT *) (ChipImageBlock + 40L);
  315.     OnTopImage.ImageData = (USHORT *) (ChipImageBlock + 80L);
  316.     OnTopSelectImage.ImageData = (USHORT *) (ChipImageBlock + 120L);
  317.     DownUnderImage.ImageData = (USHORT *) (ChipImageBlock + 160L);
  318.     DownUnderSelectImage.ImageData = (USHORT *) (ChipImageBlock + 200L);
  319.     DragWindowImage.ImageData = (USHORT *) (ChipImageBlock + 240L);
  320.     CloseWindowImage.ImageData = (USHORT *) (ChipImageBlock + 520L);
  321.     CloseWindowSelectImage.ImageData = (USHORT *) (ChipImageBlock + 560L);
  322.     JumpScreenImage.ImageData = (USHORT *) (ChipImageBlock + 600L);
  323.     JumpScreenSelectImage.ImageData = (USHORT *) (ChipImageBlock + 640L);
  324.     if ((IntuitionBase = (struct IntuitionBase *) OpenLibrary("intuition.library", 0L)) == NULL)
  325.     DoThisCodeLast(RETURN_WARN);
  326.     if ((GfxBase = (struct GfxBase *) OpenLibrary("graphics.library", 0L)) == NULL)
  327.     DoThisCodeLast(RETURN_WARN);
  328.     OpenWindowCheck(IntuitionBase->FirstScreen);
  329. }
  330.  
  331. void DoThisCodeLast(returncode)
  332. long returncode;
  333. {
  334.     if (TimerPort) {
  335.     Wait(TimerSignal);
  336.     GetMsg(TimerPort);
  337.     CloseDevice(TimerIO);
  338.     DeleteStdIO(TimerIO);
  339.     DeletePort(TimerPort);
  340.     }
  341.     if (DiskPort)
  342.     DeletePort(DiskPort);
  343.     if (DiskIO)
  344.     DeleteStdIO(DiskIO);
  345.     CloseWindowCheck();
  346.     if (GfxBase)
  347.     CloseLibrary(GfxBase);
  348.     if (IntuitionBase)
  349.     CloseLibrary(IntuitionBase);
  350.     if (ChipImageBlock)
  351.     FreeMem(ChipImageBlock, 1368L);
  352. #ifndef A1000
  353.     if (_Backstdout)
  354.     Write(_Backstdout, EGOSTRING, EGOSTRLEN);
  355. #endif
  356.     exit(returncode);
  357. }
  358.